/*
 * @Author: quit
 * @Date: 2021-11-09 16:01:11
 * @LastEditTime: 2021-12-29 15:30:55
 * @Descripttion: 路由入口文件
 */
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* 引入路由模块 */
import FdaRoutes from './modules/FdaRoutes'
import BmRoutes from './modules/BmRoutes'
import BotRoutes from './modules/BotRoutes'

/* 动态路由(页面鉴权基础) */
export const asyncRoutes = [...FdaRoutes, ...BmRoutes, ...BotRoutes]

// 静态路由
export const constantRoutes = [
    // 登录页
    {
        path: '/login',
        component: () => import('@/views/login'),
        hidden: true
    },

    // '/'重定向
    { path: '/', redirect: '/BmHome' },

    // 404 页面
    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },

    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
    new Router({
        // mode: 'history', // require service support
        scrollBehavior: () => ({ y: 0 }),
        routes: [...constantRoutes, ...asyncRoutes]
    })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
